package com.example.royalchef.adaper;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.royalchef.R;
import com.example.royalchef.base.BaseRecyclerViewAdapter;
import com.example.royalchef.base.BaseRecyclerViewHolder;
import com.example.royalchef.bean.SearchInfo;
import com.example.royalchef.utils.UIUtils;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Random;

/**
 * author: Administrator
 * created on: 2017/6/28 21:55
 * description:
 */

public class HomeAdapter extends BaseRecyclerViewAdapter<SearchInfo> {

    public HomeAdapter(ArrayList<SearchInfo> list, Context context, int layoutId) {
        super(list, context, layoutId);
    }

    @Override
    public void convert(BaseRecyclerViewHolder holder, SearchInfo homeInfo, int position, Context context) {
        TextView tvTitle = (TextView) holder.getView(R.id.tv_home_item_title);
        TextView tvFrom = (TextView) holder.getView(R.id.tv_home_item_form);
        TextView tvBrowse = (TextView) holder.getView(R.id.tv_home_item_browse);
        ImageView ivPicture = (ImageView) holder.getView(R.id.iv_home_item_picture);
        tvTitle.setText(homeInfo.getTitle());
        tvFrom.setText(homeInfo.getNickname());
        Random random = new Random();
        int nextInt = random.nextInt(10000);
        tvBrowse.setText(nextInt + "次浏览");
        Picasso.with(context)
                .load(homeInfo.getCover())
                .resize(UIUtils.dip2px(150), UIUtils.dip2px(70))
                .centerCrop()
                .config(Bitmap.Config.RGB_565)
                .into(ivPicture);
    }
}
